import {request} from "./request";

// 权限列表
function rightsListRequest(type) {
  return request({
    url: `/rights/${type}`
  })
}

// 角色列表
function rolesListRequest(){
  return request({
    url: '/roles'
  })
}

// 添加角色请求
function addRolesRequest({roleName, roleDesc}) {
  return request({
    url: '/roles',
    method: 'post',
    data: {
      roleName,
      roleDesc
    }
  })
}

// 查询角色信息
function queryRolesInfo(id) {
  return request({
    url: `/roles/${id}`
  })
}

// 修改角色信息
function editRolesInfo({roleId, roleName, roleDesc}) {
  return request({
    url: `/roles/${roleId}`,
    method: 'put',
    data: {
      roleName,
      roleDesc
    }
  })
}

// 删除角色信息
function removeRolesById(roleId) {
  return request({
    url: `/roles/${roleId}`,
    method: 'delete'
  })
}

// 删除权限
function removeRightById(roleId, rightId) {
  return request({
    url: `/roles/${roleId}/rights/${rightId}`,
    method: 'delete'
  })
}

// 角色授权
function setRolesRights(roleId, rids) {
  return request({
    url: `/roles/${roleId}/rights`,
    method: 'post',
    data: {
      rids
    }
  })
}
export {rightsListRequest, rolesListRequest, addRolesRequest,
  queryRolesInfo, editRolesInfo, removeRolesById, removeRightById, setRolesRights}